//
//  SwiftScanHelper.swift
//  ANOA
//
//  Created by 邱仙凯 on 2023/2/9.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit
import swiftScan
 
final class SwiftScanHelper:LBXScanViewControllerDelegate {
    
    private init() {}
    
    static let shared = SwiftScanHelper()
    var resultClo:((String)->())?
    
    func openScan(controller:UIViewController,resultClo:@escaping ((String)->())) {
        self.resultClo = resultClo
        //设置扫码区域参数
        var style = LBXScanViewStyle()
        style.centerUpOffset = 44
        style.photoframeAngleStyle = LBXScanViewPhotoframeAngleStyle.On
        style.photoframeLineW = 6
        style.photoframeAngleW = 24
        style.photoframeAngleH = 24
        style.isNeedShowRetangle = true
        
        style.anmiationStyle = LBXScanViewAnimationStyle.NetGrid
        
        //使用的支付宝里面网格图片
        style.animationImage = UIImage(named: "qrcode_scan_part_net")
        let vc = LBXScanViewController()
        vc.scanResultDelegate = self
        vc.scanStyle = style
        controller.navigationController?.pushViewController(vc, animated: true)
        
    }
    // 扫码结果回调
    func scanFinished(scanResult: LBXScanResult, error: String?) {
        if let clo = self.resultClo {
            clo(scanResult.strScanned.unwrap)
        }
     }
}
